/******************************************************************
 * Author: Goh Chee Hong
 * Date of creation: 1/Jan/2009

 * 
 *                                                                
 * Description: Provide method to access feed data in the database.
 ******************************************************************/
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;

namespace Pbdms.BusinessLogic.DataController
{
    /// <summary>
    /// Provide means to obtain and manage data stored in the file subscription.xml
    /// </summary>
    public class SubscriptionInfoController
    {
        /// <summary>
        /// create an instance of Buddy
        /// </summary>
        /// <returns></returns>
        public static SubscriptionInfoController create()
        {
            return new SubscriptionInfoController();
        }
        /// <summary>
        /// get the list of all subscriptions in the database
        /// </summary>
        /// <returns></returns>
        public ArrayList getListOfSubscriptionsInfo()
        {
            return DataAccess.DataProvider.SubscriptionInfoProvider.create().getListOfSubscriptionInfo();
        }
        /// <summary>
        /// update a subscription to database
        /// </summary>
        /// <param name="bdd"></param>
        public void updateSubscriptionInfoToDB(Common.DataObject.SubscriptionInfo subscr)
        {
            DataAccess.DataProvider.SubscriptionInfoProvider.create().updateSubscriptionInfoToDB(subscr);
        }
        /// <summary>
        /// append a new subscription to the database
        /// </summary>
        /// <param name="bdd"></param>
        public void appendSubscriptionInfoToDB(Common.DataObject.SubscriptionInfo subscr)
        {
            DataAccess.DataProvider.SubscriptionInfoProvider.create().appendSubscriptionInfoToDB(subscr);
        }
        public Common.DataObject.SubscriptionInfo appendSubscriptionInfoToDB(String channel, string originator)
        {
            //get next id
            int id = 0;
            System.Collections.ArrayList arlSubscriptions = BusinessLogic.DataController.SubscriptionInfoController.create().getListOfSubscriptionsInfo();
            if (arlSubscriptions != null && arlSubscriptions.Count != 0)
            {
                id = ((Common.DataObject.SubscriptionInfo)arlSubscriptions[arlSubscriptions.Count - 1]).ID + 1;
            }
            else
            {
                id = 1;
            }
            Common.DataObject.SubscriptionInfo subscr = new Pbdms.Common.DataObject.SubscriptionInfo(id, channel,originator);

            BusinessLogic.DataController.SubscriptionInfoController.create().appendSubscriptionInfoToDB(subscr);
            return subscr;
        }

        /// <summary>
        /// delete a subscription from the database
        /// </summary>
        /// <param name="bdd"></param>
        public void deleteSubscriptionInfoFromDB(Common.DataObject.SubscriptionInfo subscr)
        {
            DataAccess.DataProvider.SubscriptionInfoProvider.create().deleteSubscriptionInfoFromDB(subscr);
        }

        //select a subscription based on id
        public Common.DataObject.SubscriptionInfo selectASubscriptionInfoBasedOnIDFromDB(string id)
        {
            Common.DataObject.SubscriptionInfo subscription = DataAccess.DataProvider.SubscriptionInfoProvider.create().selectASubscriptionInfoBasedOnIDFromDB(id);

            return subscription;
        }

        //determine whether a node exists using 2 elements
        public string selectIDBasedOnChannelAndFriend(string channel, string friendID)
        {
            string temp = DataAccess.DataProvider.SubscriptionInfoProvider.create().selectIDBasedOnChannelAndFriend(channel, friendID);

            return temp;
        }


    }
}
